import settingFile from '@/setting.js'
import qs from './qs.js';

function http(options) {
	return new Promise((resolve, reject) => {
		
		var setting = {
			url: settingFile.host + options.url,
			data: options.data,
			method: options.method.toUpperCase() || 'GET',
			timeout: 6000,
			header: {
				'content-type': 'application/x-www-form-urlencoded', // from data
			},
			success(res) {
				resolve(res.data);
			},
			fail(err) {
				console.log('err',err);
				uni.showToast({
					icon:'error',
					title: '网络超时!'
				})
				reject(err);
			},
			
		}
		if (options.header) {
			setting.header = Object.assign(setting.header, options.header);
		}
		uni.request(setting);
	})
}
 

export default http;

